package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.ShopCardnumVo;
import com.ruoyi.business.service.IShopCardnumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 订单Controller
 *
 * @author Tellsea
 * @date 2025-01-22
 */
@Api(tags = "订单Controller")
@RestController
@RequestMapping("/business/cardnum")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ShopCardnumController extends BaseController {

    private final IShopCardnumService shopCardnumService;

    @ApiOperation("查询订单列表")
    @PreAuthorize("@ss.hasPermi('business:cardnum:list')")
    @GetMapping("/list")
    public TableDataInfo<ShopCardnumVo> list(ShopCardnumVo entity) {
        return shopCardnumService.queryList(entity);
    }

    @ApiOperation("查询订单所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ShopCardnumVo entity) {
        return AjaxResult.success("查询成功", shopCardnumService.queryAll(entity));
    }

    @ApiOperation("导出订单列表")
    @PreAuthorize("@ss.hasPermi('business:cardnum:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopCardnumVo entity) {
        List<ShopCardnumVo> list = shopCardnumService.queryAll(entity);
        ExcelUtil<ShopCardnumVo> util = new ExcelUtil<>(ShopCardnumVo.class);
        util.exportExcel(response, list, "订单数据");
    }

    @ApiOperation("获取订单详细信息")
    @PreAuthorize("@ss.hasPermi('business:cardnum:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", shopCardnumService.queryById(id));
    }

    @ApiOperation("新增订单")
    @PreAuthorize("@ss.hasPermi('business:cardnum:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ShopCardnumVo entity) {
        return toAjax(shopCardnumService.save(entity));
    }

    @ApiOperation("修改订单")
    @PreAuthorize("@ss.hasPermi('business:cardnum:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ShopCardnumVo entity) {
        return toAjax(shopCardnumService.updateById(entity));
    }

    @ApiOperation("删除订单")
    @PreAuthorize("@ss.hasPermi('business:cardnum:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shopCardnumService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }

//	@ApiOperation("导入订单")
//	@PreAuthorize("@ss.hasPermi('business:cardnum:remove')")
//	@Log(title = "订单", businessType = BusinessType.DELETE)
//	@PostMapping("/upload")
//	public AjaxResult upload(@RequestParam("file") MultipartFile file) {
//		return shopCardnumService.upload(file);
//	}


}
